/**
 * 
 */
package com.edocbase.desktop.plugins.mdiary;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.Figure;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import com.edocbase.desktop.lightweight.widgets.ControlFigure;
import com.edocbase.desktop.lightweight.widgets.FigureOwner;
import com.edocbase.desktop.lightweight.widgets.TabFolder;
import com.edocbase.desktop.lightweight.widgets.TabItem;
import com.edocbase.desktop.swt.widgets.RichBrowser;

public class SearchTabItem extends TabItem implements MDiaryActionConstants{
	public static final String ID = "SearchResultItem";
	private ControlFigure<Composite> browserFigure;
	RichBrowser richBrowser;
	public SearchTabItem(TabFolder folder, int style) {
		super(folder, style);
		body = new FigureOwner();
		body.setLayoutManager(new BorderLayout());
		//setId(ID);
		//setItemType(SEARCH_RESULT_ITEM_TYPE);
	}

	@Override
	public Figure getBody() {
		if (browserFigure == null) {
			if (body == null){
				return null;
			}
			Composite bodyControl = crateBody(folder.getOwner());
			browserFigure = new ControlFigure<Composite>();
			browserFigure.setControl(bodyControl);
			body.add(browserFigure, BorderLayout.CENTER);
			
		}
		return super.getBody();
	}
	protected Composite crateBody(Control parent) {
		if (richBrowser == null) {
			Composite container = (Composite) parent;
			richBrowser = new RichBrowser(container, SWT.NONE);
			configBrowser();
		}
		return richBrowser.getBrowser();
	}
	private void configBrowser() {
		
	}
	
	@Override
	public void dispose() {
		super.dispose();
		if (browserFigure != null){
			browserFigure.dispose();
			browserFigure = null;
		}
		if (richBrowser != null){
			richBrowser.dispose();
			richBrowser = null;
		}
	}

}
